#include "swpsimulationcaseeditor.h"

#include "../documents/data/graphicdata.h"
#include "items/editoritemcommon.h"

#include <gallerycommon.h>
#include <gdmodelquerymaker.h>
#include <iconmanager.h>

#include <QtCore/QMimeData>
#include <QtCore/QStringList>
#include <QtGui/QAction>
#include <QtGui/QDragEnterEvent>
#include <QtGui/QDragMoveEvent>
#include <QtGui/QDropEvent>
#include <QtGui/QGraphicsView>
#include <QtGui/QToolBar>

using namespace core;
using namespace gui;
using namespace swp;

SwpSimulationCaseEditor::SwpSimulationCaseEditor(QWidget *parent) :
    AbstractGraphicEditor(parent),
    m_createSimCasePathAction(0)
{
    IconManager* im = IconManager::getInstance();
    im->registerStyleIcon("SwpRegenerateSimCase",
        ":/swp/icons/regenerate_simulation_case_icon.png");
    im->registerStyleIcon("SwpCreateSimCasePath",
        ":/swp/icons/create_simulation_case_icon.png");

    createActions();
    connectSlots();
}

SwpSimulationCaseEditor::~SwpSimulationCaseEditor()
{

}

void SwpSimulationCaseEditor::open(
    const QSharedPointer<core::IDocument>& document)
{
    AbstractGraphicEditor::open(document);

    Q_ASSERT(m_refreshLinkedModels != 0); // bad document

    IconManager* im = IconManager::getInstance();

    m_refreshLinkedModels->setText(tr("Regenerate simulation case"));
    if (im->hasIcon("SwpRegenerateSimCase"))
    {
        m_refreshLinkedModels->setIcon(im->icon("SwpRegenerateSimCase"));
    }
}

QStringList SwpSimulationCaseEditor::galleryGroups() const
{
    QStringList ret;

    return ret;
}

QList<GalleryItem> SwpSimulationCaseEditor::galleryItems(
    const QString& group) const
{
    QList<GalleryItem> ret;

    return ret;
}

IEditor* SwpSimulationCaseEditor::copy() const
{
    return new SwpSimulationCaseEditor();
}

void SwpSimulationCaseEditor::createActions()
{
    IconManager* im = IconManager::getInstance();

    m_transformMode->setEnabled(false);
    m_escapeLastAnchor->setEnabled(false);
    m_zoomInMode->setEnabled(false);
    m_zoomOutMode->setEnabled(false);
    m_scaleToFitContent->setEnabled(false);
    m_removeSelected->setEnabled(false);
    m_selectAll->setEnabled(false);
    m_deselectAll->setEnabled(false);
    m_duplicateItem->setEnabled(false);

    m_transformMode->setVisible(false);
    m_zoomInMode->setVisible(false);
    m_zoomOutMode->setVisible(false);
    m_scaleToFitContent->setVisible(false);
    m_removeSelected->setVisible(false);
    m_selectAll->setVisible(false);
    m_deselectAll->setVisible(false);
    m_duplicateItem->setVisible(false);

    const QList<QAction*> actions = m_toolbar->actions();

    foreach (QAction* action, actions)
    {
        if (action->isSeparator())
        {
            m_toolbar->removeAction(action);
        }
    }

    //m_toolbar->addSeparator();

    m_createSimCasePathAction = new QAction(tr("Create simulation case path"),
        this);
    if (im->hasIcon("SwpCreateSimCasePath"))
    {
        m_createSimCasePathAction->setIcon(im->icon("SwpCreateSimCasePath"));
    }

    m_createSimCasePathAction->setEnabled(false);

    //m_toolbar->addAction(m_createSimCasePathAction);
}

void SwpSimulationCaseEditor::connectSlots()
{
    connect(m_createSimCasePathAction, SIGNAL(triggered()),
        this, SLOT(beginCreatingSimCasePath()));
}

// private slots
void SwpSimulationCaseEditor::beginCreatingSimCasePath()
{
    setModeToConnect(ConnectionData(CONNECTION_SIM_PATH));
}
